var tempclassname = "";
// 载入多叉树 
var setting = {
	async : {
		enable : true,
		contentType: "application/x-www-form-urlencoded",
		url : "jlgljson_loadjltreenode.action",
		autoParam : [],
		otherParam : {"table":"b_base_jl","where":"","treename":"交路"}
	},
	edit : {
		enable : false 
	},
	view : {
		// zTree 节点展开、折叠时的动画速度，设置方法同 JQuery 动画效果中 speed 参数
		expandSpeed : ""
	},
	check : {
		enable : false,
		chkStyle : "checkbox"
	},
	data : {
		simpleData : {
			enable : true
		}
	},
	callback : {  
		onClick : onClick, 
		onDblClick : onDblClick, 
		onAsyncSuccess : onAsyncSuccess
	}
};
// 完成异步加载后 
function onAsyncSuccess(event, treeId, treeNode, msg) {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var node = treeObj.getNodeByParam("name", '交路', null);
	treeObj.expandNode(node, true, false);
	selectNodeById();
}


// 双击重命名
function onDblClick(event, treeId, treeNode) {
	if (treeNode.name == '交路') {
		top.showErrorMsg('交路为系统初始化车型，不允许编辑。');
		return;
	} 
	tree_updatenode();
}

function selectByNewName(node,newName) { 
	$("#classid").val(node.name);
	var parentTreeNode = node.getParentNode();
	var treeNodeName = newName;
	var string = "";
	while (true) {
		if (parentTreeNode == null) {
			string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
			$("#category").html(string);
			return false;
		}
		string = parentTreeNode.name + ">" + string;
		parentTreeNode = parentTreeNode.getParentNode();
	}
	string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
	$("#category").html(string);
}
    
 
// 单击选择分类
// 给所属分类赋值
// 给分类id赋值
function onClick(event, treeId, treeNode) {  
	// 如果不是父节点，不存在展开一说
	var parentTreeNode = treeNode.getParentNode();
	var treeNodeName = treeNode.name;
	var string = "";
	while (true) {
		if (parentTreeNode == null) {
			break;
		}
		string = parentTreeNode.name + ">" + string;
		parentTreeNode = parentTreeNode.getParentNode();
	}
	treeNodeName=treeNodeName.replace(/</g,"&lt");
	treeNodeName=treeNodeName.replace(/>/g,"&gt");
	string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
	 $("#category").html(string);
	 $("#classid").val(treeNode.id); 
	 $('#keyword').val('');
	 $("#querytype").val("2");
	 formSearch(); 
	 var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	 treeObj.expandNode(treeNode, true, false); 
	 
}
function getChildren(ids, treeNode) {
	// 非空判断
	if (treeNode.id != null) {
		ids.push(treeNode.id);
	}
	if (treeNode.isParent) {
		for ( var obj in treeNode.children) {
			getChildren(ids, treeNode.children[obj]);
		}
	}
	return ids;
}

function selectRootNode() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var treeNode = treeObj.getNodeByParam("name", '交路', null);
	treeObj.selectNode(treeNode);
	 var parentTreeNode = treeNode.getParentNode();
	  var treeNodeName = treeNode.name;
	  var string = "";
	  while (true) {
			if (parentTreeNode == null) {
				break;
			}
			string = parentTreeNode.name + ">" + string;
			parentTreeNode = parentTreeNode.getParentNode();
		}
		treeNodeName=treeNodeName.replace(/</g,"&lt");
		treeNodeName=treeNodeName.replace(/>/g,"&gt");
		string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
		$("#category").html(string);
}

function selectNodeById() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var node = treeObj.getNodeByParam("name", $("#classid").val(), null);
	if (node == null) {
		node = treeObj.getNodeByParam("name", '交路', null);
	}
	treeObj.selectNode(node);
	if (node != null) {
		var parentTreeNode = node.getParentNode();
		var treeNodeName = node.name;
		treeNodeName=treeNodeName.replace(/</g,"&lt");
		treeNodeName=treeNodeName.replace(/>/g,"&gt");
		var string = "";
		while (true) {
			if (parentTreeNode == null) {
				string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
				$("#category").html(string);
				return false;
			}
			string = parentTreeNode.name + ">" + string;
			parentTreeNode = parentTreeNode.getParentNode();
		}
		string = string + '<span class=" fontOrange2">' + treeNodeName + '</span>';
		$("#category").html(string);
	}
}
function expandAll()
{ 
	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
	zTree.expandAll(true);
}
function collapseAll()
{
	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
	zTree.expandAll(false);
}
String.prototype.trim = function() {  
    return (this.replace(/^\s+|\s+$/g,""));  
};  